package com.edu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.edu.system.domain.TClass;
import com.edu.system.service.ITClassService;
import com.edu.system.service.ITClassroomService;
import java.util.Arrays;
import java.util.List;
import com.edu.common.utils.DateUtils;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.system.mapper.TClassGroupMapper;
import com.edu.system.domain.TClassGroup;
import com.edu.system.service.ITClassGroupService;

/**
 * 班牌编组Service业务层处理
 * 
 * @author xxxx
 * @date 2023-12-27
 */
@Service
public class TClassGroupServiceImpl implements ITClassGroupService 
{
    @Autowired
    private TClassGroupMapper tClassGroupMapper;
    @Resource
    private ITClassService itClassService;
    @Resource
    private ITClassroomService itClassroomService;

    /**
     * 查询班牌编组
     * 
     * @param id 班牌编组主键
     * @return 班牌编组
     */
    @Override
    public TClassGroup selectTClassGroupById(Long id)
    {
        TClassGroup row = tClassGroupMapper.selectTClassGroupById(id);
        row.setClassNames(itClassService.queryTClassNames(row.getClassIds()));
        return row;
    }

    @Override
    public List<TClassGroup> listByIds(List<Long> ids) {
        return tClassGroupMapper.listByIds(ids);
    }

    /**
     * 查询班牌编组列表
     * 
     * @param tClassGroup 班牌编组
     * @return 班牌编组
     */
    @Override
    public List<TClassGroup> selectTClassGroupList(TClassGroup tClassGroup)
    {
        List<TClassGroup> list = tClassGroupMapper.selectTClassGroupList(tClassGroup);
        return list;
    }

    @Override
    public List<TClassGroup> showTClassGroupList(TClassGroup tClassGroup)
    {
        List<TClassGroup> list = this.selectTClassGroupList(tClassGroup);
        // 班级组 id 转 name
        list.forEach(a -> a.setClassNames(itClassroomService.queryRoomNamesByIds(a.getClassIds())));
        return list;
    }

    /**
     * 新增班牌编组
     * 
     * @param tClassGroup 班牌编组
     * @return 结果
     */
    @Override
    public int insertTClassGroup(TClassGroup tClassGroup)
    {
        tClassGroup.setCreateTime(DateUtils.getNowDate());
        return tClassGroupMapper.insertTClassGroup(tClassGroup);
    }

    /**
     * 修改班牌编组
     * 
     * @param tClassGroup 班牌编组
     * @return 结果
     */
    @Override
    public int updateTClassGroup(TClassGroup tClassGroup)
    {
        tClassGroup.setUpdateTime(DateUtils.getNowDate());
        return tClassGroupMapper.updateTClassGroup(tClassGroup);
    }

    /**
     * 批量删除班牌编组
     * 
     * @param ids 需要删除的班牌编组主键
     * @return 结果
     */
    @Override
    public int deleteTClassGroupByIds(Long[] ids)
    {
        return tClassGroupMapper.deleteTClassGroupByIds(ids);
    }

    /**
     * 删除班牌编组信息
     * 
     * @param id 班牌编组主键
     * @return 结果
     */
    @Override
    public int deleteTClassGroupById(Long id)
    {
        return tClassGroupMapper.deleteTClassGroupById(id);
    }
}
